class Solution {
public
    int removeDuplicates(vectorint& nums) {
        int i = 0, j = 0;
        while(j  nums.size()){
            if(j  nums.size() - 1 && nums[j + 1] == nums[j]){
                nums[i++] = nums[j++];
                nums[i++] = nums[j];
                int temp = nums[j];
                while(j  nums.size() && nums[j] == temp)j++;
            }
            else nums[i++] = nums[j++];
        }
        return i;
    }
};

//2021.4.6
